const express = require("express");
const {graphqlHTTP} = require("express-graphql");
const {buildSchema} = require("graphql");

var i = 0;

const schema = buildSchema(`
    type Query{
        hello: String
        hello2: String
    }   
`);

const root = {
    hello: () => {
        i += 1;
        return "Hello, world!" + i;
    },
    hello2:()=>{
        i+= 2;
        return "你好，世界！" + i;
    }
};

const app = express();

app.use("/graphql",graphqlHTTP({
    schema:schema,
    rootValue:root,
    graphiql: true,
}));

console.log("启动服务器")
app.listen(4000);

